package scm.client;

import java.util.ArrayList;
import java.util.Date;

import scm.message.*;
import scm.server.Lista;
import scm.server.MailServer;
/**
 * 
 * @author Benito
 *
 */
public class MailClient {

	
	
	private Lista messagelist = null;
	
	private String name; 
	private MailServer server;
	
	public MailClient(String username, MailServer server){
		this.name = username;
		messagelist = new Lista();
		this.server = server;
		this.server.conect(this);
	}
	
	public int checkMessage(){
		return messagelist.cantidad();
	}
	
	public void reciveMessage(Message message){
		int clave = checkMessage();
		messagelist.addicionar(Integer.toString(clave+1), message); 
	}
	
	public Message readNextMessage(){
		Message message = (Message)messagelist.devolverSiguiente();
		return message;
	}
	
	public void sendMessage(Message message){
		server.post(message);
	}

	@Override
	public String toString(){
		return name;
	}
	
}
